import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;


public class EmailClass {

    
    public void Mailer(String to, String[] results ){
    	
    	//check array before this method is called to make sure that results array is not empty
    	String body=null;
        String from = "keskpeart@ufl.edu";
        String host = "smtp.ufl.edu";
        
        //create message body from results array;
        for(int i=0;i<results.length;i++){
        	
        	if(results[i]==null)break;
        	else if(i==0)body=results[i];
        	else body=body+"\n"+results[i];
        }

        // Create properties, get Session
        Properties props = new Properties();
        props.put("mail.smtp.host", host);
        // To see what is going on behind the scene
        //props.put("mail.debug", "true");
        Session session = Session.getInstance(props);

        try {
        	
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject("New Post");
            msg.setSentDate(new Date());
            msg.setText(body);
            
            if(body!=null)
            Transport.send(msg);
        }
        catch (MessagingException mex) {
            
            mex.printStackTrace();
        }
    }
}

